/*
 * 英才汇硕信息科技有限公司 拥有本软件版权 2021 并保留所有权利。
 * Copyright 2021, YCHS Information&Science Techology Co.,Ltd,
 * All right reserved.
 */
package com.ychs.lawyerback.controller;

import com.ychs.lawyerback.common.R;
import com.ychs.lawyerback.dto.SealOptDTO;
import com.ychs.lawyerback.dto.SealQueryDTO;
import com.ychs.lawyerback.service.SealService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author mayujing
 * @version 1.0
 */
@RestController
@RequestMapping("/seal")
public class SealController {

    @Autowired
    private SealService sealService;

    /**
     * 分页查询印章使用记录
     * @param sealQueryDTO
     * @return
     */
    @GetMapping("/list")
    public R<?> getSealsByCondition(SealQueryDTO sealQueryDTO) {
        Map<String, Object> result = sealService.getSealsByCondition(sealQueryDTO);
        return R.success(result);
    }

    @PostMapping("/addSeal")
    public R<?> addSeal(@Valid @RequestBody SealOptDTO sealOptDTO) {
        long res = sealService.addSeal(sealOptDTO);
        return res > 0 ? R.success() : R.fail();
    }

    @PutMapping("/editSeal")
    public R<?> editSeal(@Valid @RequestBody SealOptDTO sealOptDTO) {
        int rows = sealService.editSeal(sealOptDTO);
        return rows > 0 ? R.success() : R.fail();
    }

    @GetMapping("/{id}")
    public R<?> geRecordDetail(@PathVariable Long id) {
        return R.success(sealService.getSealById(id));
    }
}
